package com.useeinfo.oa.modules.repair.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.base.entity.DictInfo;
import com.useeinfo.oa.modules.base.entity.Enterprise;
import com.useeinfo.oa.modules.security.entity.SystemUser;

import javax.persistence.*;

/**
 * @Auther: xudong.sun
 * @Date: 2018/12/17 13:13
 * @Description: 维修参与人
 */
@Entity
@Table(name = "repair_partner")
public class RepairPartner extends SuperClassEntity<RepairPartner> {

    /**
     * 申请原因
     */
    private String reason;

    /**
     * 协作类型
     */
    @ManyToOne
    @JoinColumn(name = "teamwork_cat")
    private DictInfo teamworkCat;

    @ManyToOne
    @JoinColumn(name = "repair_order_id")
    private  RepairOrder repairOrder;


    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;


    @ManyToOne
    @JoinColumn(name = "partner_id")
    private SystemUser partner;

    /**
     * 我的工时
     */
    private long workingHours;

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public DictInfo getTeamworkCat() {
        return teamworkCat;
    }

    public void setTeamworkCat(DictInfo teamworkCat) {
        this.teamworkCat = teamworkCat;
    }

    public RepairOrder getRepairOrder() {
        return repairOrder;
    }

    public void setRepairOrder(RepairOrder repairOrder) {
        this.repairOrder = repairOrder;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    public SystemUser getPartner() {
        return partner;
    }

    public void setPartner(SystemUser partner) {
        this.partner = partner;
    }

    public long getWorkingHours() {
        return workingHours;
    }

    public void setWorkingHours(long workingHours) {
        this.workingHours = workingHours;
    }

    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject =  super.toJSONObject();
        jsonObject.put("userName", StringConverters.null2String(partner.getUserName()));
        jsonObject.put("mobile", StringConverters.null2String(partner.getMobile()));
        jsonObject.put("reason", StringConverters.null2String(getReason()));
        jsonObject.put("teamworkCatName", StringConverters.null2String(getTeamworkCat().getPropertyName()));
        jsonObject.put("workingHours", StringConverters.null2String(getWorkingHours()));
        return jsonObject;
    }
}
